package after_sale_order

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/after_sale_order"
    after_sale_orderReq "github.com/flipped-aurora/gin-vue-admin/server/model/after_sale_order/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type AfterSaleOrderApi struct {}



// CreateAfterSaleOrder 创建售后管理
// @Tags AfterSaleOrder
// @Summary 创建售后管理
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body after_sale_order.AfterSaleOrder true "创建售后管理"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /afterSaleOrders/createAfterSaleOrder [post]
func (afterSaleOrdersApi *AfterSaleOrderApi) CreateAfterSaleOrder(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var afterSaleOrders after_sale_order.AfterSaleOrder
	err := c.ShouldBindJSON(&afterSaleOrders)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = afterSaleOrdersService.CreateAfterSaleOrder(ctx,&afterSaleOrders)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteAfterSaleOrder 删除售后管理
// @Tags AfterSaleOrder
// @Summary 删除售后管理
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body after_sale_order.AfterSaleOrder true "删除售后管理"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /afterSaleOrders/deleteAfterSaleOrder [delete]
func (afterSaleOrdersApi *AfterSaleOrderApi) DeleteAfterSaleOrder(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	afterSaleId := c.Query("afterSaleId")
	err := afterSaleOrdersService.DeleteAfterSaleOrder(ctx,afterSaleId)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteAfterSaleOrderByIds 批量删除售后管理
// @Tags AfterSaleOrder
// @Summary 批量删除售后管理
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /afterSaleOrders/deleteAfterSaleOrderByIds [delete]
func (afterSaleOrdersApi *AfterSaleOrderApi) DeleteAfterSaleOrderByIds(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	afterSaleIds := c.QueryArray("afterSaleIds[]")
	err := afterSaleOrdersService.DeleteAfterSaleOrderByIds(ctx,afterSaleIds)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateAfterSaleOrder 更新售后管理
// @Tags AfterSaleOrder
// @Summary 更新售后管理
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body after_sale_order.AfterSaleOrder true "更新售后管理"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /afterSaleOrders/updateAfterSaleOrder [put]
func (afterSaleOrdersApi *AfterSaleOrderApi) UpdateAfterSaleOrder(c *gin.Context) {
    // 从ctx获取标准context进行业务行为
    ctx := c.Request.Context()

	var afterSaleOrders after_sale_order.AfterSaleOrder
	err := c.ShouldBindJSON(&afterSaleOrders)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = afterSaleOrdersService.UpdateAfterSaleOrder(ctx,afterSaleOrders)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindAfterSaleOrder 用id查询售后管理
// @Tags AfterSaleOrder
// @Summary 用id查询售后管理
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param afterSaleId query int true "用id查询售后管理"
// @Success 200 {object} response.Response{data=after_sale_order.AfterSaleOrder,msg=string} "查询成功"
// @Router /afterSaleOrders/findAfterSaleOrder [get]
func (afterSaleOrdersApi *AfterSaleOrderApi) FindAfterSaleOrder(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	afterSaleId := c.Query("afterSaleId")
	reafterSaleOrders, err := afterSaleOrdersService.GetAfterSaleOrder(ctx,afterSaleId)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reafterSaleOrders, c)
}
// GetAfterSaleOrderList 分页获取售后管理列表
// @Tags AfterSaleOrder
// @Summary 分页获取售后管理列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query after_sale_orderReq.AfterSaleOrderSearch true "分页获取售后管理列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /afterSaleOrders/getAfterSaleOrderList [get]
func (afterSaleOrdersApi *AfterSaleOrderApi) GetAfterSaleOrderList(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

	var pageInfo after_sale_orderReq.AfterSaleOrderSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := afterSaleOrdersService.GetAfterSaleOrderInfoList(ctx,pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetAfterSaleOrderPublic 不需要鉴权的售后管理接口
// @Tags AfterSaleOrder
// @Summary 不需要鉴权的售后管理接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /afterSaleOrders/getAfterSaleOrderPublic [get]
func (afterSaleOrdersApi *AfterSaleOrderApi) GetAfterSaleOrderPublic(c *gin.Context) {
    // 创建业务用Context
    ctx := c.Request.Context()

    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    afterSaleOrdersService.GetAfterSaleOrderPublic(ctx)
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的售后管理接口信息",
    }, "获取成功", c)
}
